home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / lang / amigatalk.lha / intuition / BitMap.st < prev    next >
Text File  |  2003-11-21  |  5KB  |  168 lines

  1. "---------------------------------------------------------------"
  2. " BitMap Class implements control of Amiga BitMaps.             "
  3. " ------------------------------------------------------------- "
  4. " See BitMapFlags class after this class for valid values for   "
  5. " Flags "
  6.  
  7. " Test file:
  8.   bmap   <- BitMap      new
  9.   bflags <- BitMapFlags new
  10.  
  11.   flags <-         bflags bitMapFlag: #BMF_DISPLAYABLE
  12.   flags <- flags + bflags bitMapFlag: #BMF_INTERLEAVED
  13.   flags <- flags + bflags bitMapFlag: #BMF_STANDARD
  14.               
  15.   bmap setBitMapWidth:  540
  16.   bmap setBitMapHeight: 90
  17.   bmap setBitMapDepth:  8
  18.   bmap setBitMapFlags:  flags
  19.   bmap makeBitMap
  20.   ...
  21.   bmap dispose
  22. "
  23. " More methods to obtain data from the system have to be added, "
  24. " such as reading IFF files & transforming them into something  "
  25. " that this class can use to write it's own custom files.       "
  26. "---------------------------------------------------------------"
  27.  
  28. Class BitMap :Glyph  ! private width height depth flags !
  29. [
  30.    dispose
  31.  
  32.       <primitive 189 0 private>.
  33.       
  34.       <primitive 250 5 0 private>.
  35.       
  36.       ^ nil
  37. |
  38.    getBitMapWidth
  39.       ^ width <- <primitive 189 2 0 private>
  40. |
  41.    getBitMapHeight
  42.       ^ height <- <primitive 189 2 1 private>
  43. |
  44.    getBitMapFlags
  45.       ^ flags <- <primitive 189 2 2 private>
  46. |
  47.    getBitMapDepth
  48.       ^ depth <- <primitive 189 2 3 private>
  49. |
  50.    changeBitMapWidth: newWidth
  51.       <primitive 189 3 0 newWidth private>.
  52.       width <- newWidth
  53. |
  54.    changeBitMapHeight: newHeight
  55.       <primitive 189 3 1 newHeight private>.
  56.       height <- newHeight
  57. |
  58.    changeBitMapFlags: newFlags
  59.       <primitive 189 3 2 newFlags private>.
  60.       flags <- newFlags
  61. |
  62.    changeBitMapDepth: newDepth
  63.       <primitive 189 3 3 newDepth private>.
  64.       depth <- newDepth
  65. |
  66.    changeDataTo: longWord at: offset
  67.       ^ <primitive 189 10 longWord offset private>
  68. |
  69.    readBitMapFile: bitMapFileName
  70.       (<primitive 189 4 bitMapFileName private> == false)
  71.          ifTrue: [ ^ nil ].
  72.  
  73.       width  <- <primitive 189 2 0 private>.
  74.       height <- <primitive 189 2 1 private>.
  75.       flags  <- <primitive 189 2 2 private>.
  76.       depth  <- <primitive 189 2 3 private>.
  77.  
  78.       ^ self
  79. |
  80.    writeBitMapFile: bitMapFileName
  81.       <primitive 189 5 bitMapFileName private>
  82. |
  83.    setBitMapWidth: newWidth
  84.       width <- newWidth
  85. |
  86.    setBitMapHeight: newHeight
  87.       height <- newHeight
  88.  
  89. |
  90.    setBitMapFlags: newFlags
  91.       flags <- newFlags
  92. |
  93.    setBitMapDepth: newDepth
  94.       depth <- newDepth
  95. |
  96.    makeBitMap
  97.       private <- <primitive 189 1 width height depth flags>.
  98.       ^ self
  99. |
  100.    getBitMapObject
  101.       ^ private
  102. |
  103.    stealBitMapFromWindow: windowObj
  104.       private <- <primitive 189 6 windowObj>.
  105.       ^ private
  106. |
  107.    stealBitMapFromScreen: screenObj
  108.       private <- <primitive 189 7 screenObj>.
  109.       ^ private
  110. |
  111.    stealBitMapFromWindowTitled: windowTitle
  112.       private <- <primitive 189 8 windowTitle>.
  113.       ^ private
  114. |
  115.    stealBitMapFromScreenTitled: screenTitle
  116.       private <- <primitive 189 9 screenTitle>.
  117.       ^ private
  118. ]
  119.  
  120. " ------------------------------------------------------------------- "
  121. " BitMapFlags Class is a Singleton class that allows the user to      "
  122. " reference BitMap Flags' hexadecimal values.                         "
  123. ""
  124. " ALL singleton classes MUST contain the following:                   "
  125. ""
  126. "   the methods:  isSingleton AND privateSetup     AND                "
  127. "                 uniqueInstance Class instance variable.             "
  128. " ------------------------------------------------------------------- "
  129.  
  130. Class BitMapFlags :Dictionary ! uniqueInstance !
  131. [
  132.    isSingleton
  133.      ^ true  
  134. |
  135.    bitMapFlag: keySymbol
  136.      ^ (self at: keySymbol)  
  137. |
  138.    privateNew ! newinstance !
  139.      newinstance <- super new.
  140.  
  141.      ^ newinstance
  142. |
  143.    new
  144.      ^ self privateSetup
  145. |
  146.    privateSetup
  147.      (uniqueInstance isNil)
  148.        ifTrue: [uniqueInstance <- self privateNew.
  149.  
  150.                 " flags for AllocBitMap, etc. "
  151.  
  152.                 self at: #BMF_CLEAR       put: 1.
  153.                 self at: #BMF_DISPLAYABLE put: 2.
  154.                 self at: #BMF_INTERLEAVED put: 4.
  155.                 self at: #BMF_STANDARD    put: 8.
  156.                 self at: #BMF_MINPLANES   put: 16.
  157.  
  158.                 " the following are for GetBitMapAttr() "
  159.  
  160.                 self at: #BMA_HEIGHT      put: 0.
  161.                 self at: #BMA_DEPTH       put: 4.
  162.                 self at: #BMA_WIDTH       put: 8.
  163.                 self at: #BMA_FLAGS       put: 12.
  164.                ].
  165.                
  166.      ^ self    "or ^ uniqueInstance??"
  167. ]
  168.